package com.br.estoque.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.br.estoque.bean.Modelo;

public class ModeloDAO extends DataUtils {

	public List<Modelo> getAll(){
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Modelo modelo = null;
		List<Modelo> lista = new ArrayList<Modelo>();
		try{
			conn = getConnection();
			stmt = conn.prepareStatement("SELECT * FROM modelo");
			rs = stmt.executeQuery();
			while(rs.next()){
				modelo = new Modelo();
				modelo.setId(rs.getInt("codigo"));
				modelo.setModelo(rs.getString("modelo"));
				modelo.setMarca(rs.getInt("marca"));
				modelo.setTipo(rs.getInt("tipo"));
				lista.add(modelo);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				conn.close();
				stmt.close();
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return lista;
	}
}
